/*
 * ---------------------------------------------------------------------
 * Copyright (c) 2014, 2015 All Right Reserved
 * This software is developed for study and improve coding skill ...
 *
 * Project:  Excellent Coding< EC >
 *
 * ecMsgProcCQ.cpp
 * This file for thread message processor with CQueue interface imp.
 *
 * Eamil:   epengao@126.com
 * Author:  Peter Gao
 * Version: Intial first version.
 * --------------------------------------------------------------------
 */

#include "ecMsgProcCQ.h"

namespace ec {

ecMsgProcCQ::ecMsgProcCQ(EC_U32 nMaxSize)
:m_cMessageList(nMaxSize)
{
}

ecMsgProcCQ::~ecMsgProcCQ()
{
    ClearMsg();
}

void ecMsgProcCQ::ClearMsg()
{
    ecMessage *pMsg = EC_NULL;
    m_cMessageList.DeleteItemFromHead(&pMsg);
    while(EC_NULL != pMsg)
    {
        delete pMsg;
        pMsg = EC_NULL;
        m_cMessageList.DeleteItemFromHead(&pMsg);
    }
}

ecMessage* ecMsgProcCQ::GetMsg()
{
    ecMessage* pMsg = EC_NULL;
    m_cMessageList.DeleteItemFromHead(&pMsg);
    return pMsg;
}

EC_U32 ecMsgProcCQ::PostMsg(ecMessage* pMsg)
{
    return m_cMessageList.AddItemToTail(&pMsg);
}

} /* namespace ec */